home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / gui-documents.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  28.5 KB  |  941 lines

  1. // MDF - PORT FROM NCSA VERSION 2.1
  2. // Some functions still need work...
  3.  
  4. #include "includes.h"
  5. #include "HTML.h"
  6. #include "mosaic.h"
  7. #include "globals.h"
  8. #include "htmlgad.h"
  9. #include "gui.h"
  10. #include "XtoI.h"
  11. #include "protos.h"
  12.  
  13. extern void ResetAmigaGadgets(void);
  14.  
  15. extern char *cached_url;
  16. extern int binary_transfer;
  17. extern char *startup_document, *home_document;
  18. extern void ShowHtml_RG(void);
  19. // extern Display *dsp;
  20.  
  21. int loading_inlined_images = 0;
  22. char *url_base_override = NULL;
  23. int interrupted = 0;
  24. #define mui_version (MUIMasterBase->lib_Version)
  25.  
  26. extern char *mo_post_pull_er_over (char *url, char *content_type, 
  27.                                    char *post_data, 
  28.                                    char **texthead);
  29.  
  30. /****************************************************************************
  31.  * name:    mo_snarf_scrollbar_values
  32.  * purpose: Store current viewing state in the current node, in case
  33.  *          we want to return to the same location later.
  34.  * inputs:  
  35.  *   - mo_window *win: Current window.
  36.  * returns: 
  37.  *   mo_succeed
  38.  *   (mo_fail if no current node exists)
  39.  * remarks: 
  40.  *   Snarfs current docid position in the HTML widget.
  41.  ****************************************************************************/
  42. mo_status mo_snarf_scrollbar_values (mo_window *win)
  43. {
  44.   HTMLGadClData *HTML_Data=INST_DATA(HTMLGadClass,HTML_Gad);
  45.   /* Make sure we have a node. */
  46.   if (!win->current_node)
  47.     return mo_fail;
  48.  
  49.   win->current_node->docid = HTMLPositionToId(win->scrolled_win, 0, HTML_Data->scroll_y);
  50.  
  51.   /* Do the cached stuff thing. */
  52.   win->current_node->cached_stuff = HTMLGetWidgetInfo (win->scrolled_win);
  53.  
  54.   return mo_succeed;
  55. }
  56.  
  57.  
  58. /* ---------------------- mo_reset_document_headers ----------------------- */
  59.  
  60. static mo_status mo_reset_document_headers (mo_window *win)
  61. {
  62.     if (win->current_node){
  63.         if(TX_Title)
  64.             set(TX_Title, MUIA_Text_Contents, win->current_node->title);
  65.         else
  66.             set(WI_Main, MUIA_Window_Title, win->current_node->title);
  67.  
  68.         set(TX_URL, MUIA_String_Contents, win->current_node->url);
  69.         }
  70.     return mo_succeed;
  71. }
  72.  
  73. /* --------------------------- mo_back_possible --------------------------- */
  74.  
  75. /* This could be cached, but since it shouldn't take too long... */
  76. static void mo_back_possible (mo_window *win)
  77. {
  78.   set(BT_Back, MUIA_Disabled, FALSE);
  79.   DoMethod(App, MUIM_Application_SetMenuState, mo_back, TRUE);
  80.   return;
  81. }
  82.  
  83.  
  84. /****************************************************************************
  85.  * name:    mo_back_impossible
  86.  * purpose: Can't go back (nothing in the history list).
  87.  ****************************************************************************/
  88. mo_status mo_back_impossible (mo_window *win)
  89. {
  90.   set(BT_Back, MUIA_Disabled, TRUE);
  91.   DoMethod(App, MUIM_Application_SetMenuState, mo_back, FALSE);
  92.   return mo_succeed;
  93. }
  94.  
  95. static void mo_forward_possible (mo_window *win)
  96. {
  97.   set(BT_Forward, MUIA_Disabled, FALSE);
  98.   DoMethod(App, MUIM_Application_SetMenuState, mo_forward, TRUE);
  99.   return;
  100. }
  101.  
  102.  
  103. /****************************************************************************
  104.  * name:    mo_forward_impossible
  105.  * purpose: Can't go forward (nothing in the history list).
  106.  ****************************************************************************/
  107. mo_status mo_forward_impossible (mo_window *win)
  108. {
  109.   set(BT_Forward, MUIA_Disabled, TRUE);
  110.   DoMethod(App, MUIM_Application_SetMenuState, mo_forward, FALSE);
  111.   return mo_succeed;
  112. }
  113.  
  114. /* ---------------------- mo_annotate_edit_possible ----------------------- */
  115.  
  116. static void mo_annotate_edit_possible (mo_window *win)
  117. {
  118. //  XmxRSetSensitive (win->menubar, mo_annotate_edit, XmxSensitive);
  119. //  XmxRSetSensitive (win->menubar, mo_annotate_delete, XmxSensitive);
  120.   return;
  121. }
  122.  
  123. static void mo_annotate_edit_impossible (mo_window *win)
  124. {
  125. //  XmxRSetSensitive (win->menubar, mo_annotate_edit, XmxNotSensitive);
  126. //  XmxRSetSensitive (win->menubar, mo_annotate_delete, XmxNotSensitive);
  127.   return;
  128. }
  129.  
  130.  
  131. /* ------------------------------------------------------------------------ */
  132.  
  133. static void mo_set_text (Object *HTML_Gad, char *txt, char *ans, int id, 
  134.                          char *target_anchor, void *cached_stuff)
  135. {
  136.   struct Window *win;
  137.   HTMLGadClData *HTML_Data =INST_DATA(HTMLGadClass,HTML_Gad);
  138.   
  139.  
  140.   /* Any data transfer that takes place in here must be inlined
  141.      image loading. */
  142.   loading_inlined_images = 1;
  143.   interrupted = 0;
  144.   mo_set_image_cache_nuke_threshold ();
  145.   if (Rdata.annotations_on_top)
  146.     HTMLSetText (HTML_Data, txt, ans ? ans : "\0", "\0", id, target_anchor, 
  147.                  cached_stuff);
  148.   else
  149.     HTMLSetText (HTML_Data, txt, "\0", ans ? ans : "\0", id, target_anchor, 
  150.                  cached_stuff);
  151.   loading_inlined_images = 0;
  152.   interrupted = 0;
  153.   mo_gui_done_with_icon ();
  154. }
  155.  
  156.  
  157. /****************************************************************************
  158.  * name:    mo_do_window_text (PRIVATE)
  159.  * purpose: Set a window's text and do lots of other housekeeping
  160.  *          and GUI-maintenance things.
  161.  * inputs:  
  162.  *   - mo_window *win: The current window.
  163.  *   - char      *url: The URL for the text; assumed to be canonicalized
  164.  *                     and otherwise ready for inclusion in history lists,
  165.  *                     the window's overhead URL display, etc.
  166.  *   - char      *txt: The new text for the window.
  167.  *   - char  *txthead: The start of the malloc'd block of text corresponding
  168.  *                     to txt.
  169.  *   - int register_visit: If TRUE, then this text should be registerd
  170.  *                         as a new node in the history list.  If FALSE,
  171.  *                         then we're just moving around in the history list.
  172.  *   - char      *ref: Reference (possible title) for this text.
  173.  * returns: 
  174.  *   mo_succeed
  175.  * remarks: 
  176.  *   This is the mother of all functions in Mosaic.  Probably should be
  177.  *   rethought and broken down.
  178.  ****************************************************************************/
  179. static mo_status mo_do_window_text (mo_window *win, char *url, char *txt,
  180.                                     char *txthead,
  181.                                     int register_visit, char *ref)
  182. {
  183.   char *ans;
  184.  
  185.   mo_set_current_cached_win (win);
  186.  
  187.   if (Rdata.track_pointer_motion)
  188.     {
  189. /*
  190.       XmString xmstr = XmStringCreateLtoR (" ", XmSTRING_DEFAULT_CHARSET);
  191.       XtVaSetValues
  192.         (win->tracker_label,
  193.          XmNlabelString, (XtArgVal)xmstr,
  194.          NULL);
  195.       XmStringFree (xmstr);
  196. */
  197.     }
  198.       
  199.   /* If !register_visit, we're just screwing around with current_node
  200.      already, so don't bother snarfing scrollbar values. */
  201.   if (register_visit)
  202.     mo_snarf_scrollbar_values (win);
  203.  
  204.   /* cached_url HAS to be set here, since Resolve counts on it. */
  205.   cached_url = mo_url_canonicalize (url, "");
  206.   win->cached_url = cached_url;
  207.  
  208.   mo_here_we_are_son (url);
  209.   
  210.   {
  211.     /* Since mo_fetch_annotation_links uses the communications code,
  212.        we need to play games with binary_transfer. */
  213.     int tmp = binary_transfer;
  214.     binary_transfer = 0;
  215.     ans = NULL;
  216. //    ans = mo_fetch_annotation_links (url, Rdata.annotations_on_top);
  217.     binary_transfer = tmp;
  218.   }
  219.  
  220.   /* If there is a BASE tag in the document that contains a "real"
  221.      URL, this will be non-NULL by the time we exit and base_callback
  222.      will have been called. */
  223.   url_base_override = NULL;
  224.  
  225.   {
  226.     int id = 0, freeta = 0;
  227.     void *cached_stuff = NULL;
  228.     char *target_anchor = win->target_anchor;
  229.  
  230.     if ((!register_visit) && win->current_node)
  231.       {
  232.         id = win->current_node->docid;
  233.         cached_stuff = win->current_node->cached_stuff;
  234.       }
  235.  
  236.     /* If the window doesn't have a target anchor already,
  237.        see if there's one in this node's URL. */
  238.     if ((!target_anchor || !(*target_anchor)) && win->current_node)
  239.       {
  240.         target_anchor = mo_url_extract_anchor (win->current_node->url);
  241.         freeta = 1;
  242.       }
  243.  
  244.     if (!txt || !txthead)
  245.       {
  246. #if 0
  247.         txt = strdup ("<h1>Uh oh, I'm stumped</h1> Mosaic has encountered a situation in which it doesn't know what to do.  Please back up and try again, or send a bug report including full details about what you're trying to do to <b>mosaic-x@ncsa.uiuc.edu</b>.  We thank you for your support.");
  248. #endif
  249.         /* Just make it look OK...  band-aid city. */
  250.         txt = strdup ("\0");
  251.         txthead = txt;
  252.       }
  253.  
  254.     mo_set_text (win->HTML_Gad, txt, ans, id, target_anchor,
  255.                  cached_stuff);
  256.  
  257.     if (win->target_anchor)
  258.       free (win->target_anchor);
  259.  
  260.     win->target_anchor = NULL;
  261.  
  262.     if (freeta)
  263.       free (target_anchor);
  264.   }
  265.  
  266.   if (url_base_override)
  267.     {
  268.       /* Get the override URL -- this should be all we need to do here. */
  269.       url = url_base_override;
  270.       mo_here_we_are_son (url);
  271.     }
  272.  
  273.   /* Every time we view the document, we reset the search_start
  274.      struct so searches will start at the beginning of the document. */
  275.   TO_HTML_reset_search(win);
  276.   /* CURRENT_NODE ISN'T SET UNTIL HERE (assuming register_visit is 1). */
  277.   /* Now that WbNtext has been set, we can pull out WbNtitle. */
  278.   /* First, check and see if we have a URL.  If not, we probably
  279.      are only jumping around inside a document. */
  280.   if (url && *url)
  281.     {
  282.       if (register_visit)
  283.         mo_record_visit (win, url, txt, txthead, ref);
  284.       else
  285.         {
  286.           /* At the very least we want to pull out the new title,
  287.              if one exists. */
  288.           if (win->current_node)
  289.             {
  290.               if (win->current_node->title)
  291.                 free (win->current_node->title);
  292.               win->current_node->title = mo_grok_title (win, url, ref);
  293.             }
  294.         }
  295.     }
  296.   
  297.   mo_reset_document_headers (win);
  298.  
  299.   if (win->history_list && win->current_node)
  300.     {
  301.       int n, i;
  302.  
  303.       get(win->history_list, MUIA_List_Entries, &n);
  304.       for (i=0; i<n; i++) {
  305.     DoMethod(win->history_list, MUIM_List_Select, i,
  306.          MUIV_List_Select_Off, NULL);
  307.       }
  308.       set(win->history_list, MUIA_List_Active, MUIV_List_Active_Off);
  309.       DoMethod(win->history_list, MUIM_List_Select,
  310.            win->current_node->position - 1, MUIV_List_Select_On, NULL);
  311.     }
  312.  
  313.   /* Update source text if necessary. */
  314.   if (win->source_text && win->current_node)
  315.     {
  316.       set(win->source_text, MUIA_Floattext_Text, win->current_node->text);
  317.     }
  318.  
  319.   if (win->current_node && win->current_node->previous != NULL)
  320.     mo_back_possible (win);
  321.   else
  322.     mo_back_impossible (win);
  323.   
  324.   if (win->current_node && win->current_node->next != NULL)
  325.     mo_forward_possible (win);
  326.   else
  327.     mo_forward_impossible (win);
  328.  
  329. /*
  330.   if (win->current_node && 
  331.       mo_is_editable_annotation (win, win->current_node->text))
  332.     mo_annotate_edit_possible (win);
  333.   else
  334.     mo_annotate_edit_impossible (win);
  335. */
  336.   mo_not_busy ();
  337.  
  338.   return mo_succeed;
  339. }
  340.  
  341.  
  342. /****************************************************************************
  343.  * name:    mo_set_win_current_node
  344.  * purpose: Given a window and a node, set the window's current node.
  345.  *          This assumes node is already all put together, in the history
  346.  *          list for the window, etc.
  347.  * inputs:  
  348.  *   - mo_window *win: The current window.
  349.  *   - mo_node  *node: The node to use.
  350.  * returns: 
  351.  *   Result of calling mo_do_window_text.
  352.  * remarks: 
  353.  *   This routine is meant to be used to move forward, backward,
  354.  *   and to arbitrarily locations in the history list.
  355.  ****************************************************************************/
  356.  
  357. mo_status mo_set_win_current_node (mo_window *win, mo_node *node)
  358. {
  359.   void *to_free = NULL;
  360.   mo_status r;
  361.  
  362.   mo_snarf_scrollbar_values (win);
  363.  
  364.   if (win->current_node && win->reloading)
  365.     {
  366.       to_free = win->current_node->cached_stuff;
  367.  
  368.       win->current_node->cached_stuff = NULL;
  369.     }
  370.  
  371.   win->current_node = node;
  372.  
  373.   mo_busy ();
  374.   mo_set_current_cached_win (win);
  375.   r = mo_do_window_text (win, win->current_node->url, 
  376.                          win->current_node->text, 
  377.              win->current_node->texthead,
  378.              FALSE, win->current_node->ref);
  379.  
  380.   if (win->reloading)
  381.     {
  382. //      if (to_free)
  383. //        HTMLFreeWidgetInfo (to_free);
  384.       
  385.       win->reloading = 0;
  386.     }
  387.  
  388.   ShowHtml_RG();
  389.  
  390.   return r;
  391. }
  392.  
  393.  
  394. /****************************************************************************
  395.  * name:    mo_reload_window_text
  396.  * purpose: Reload the current window's text by pulling it over the
  397.  *          network again.
  398.  * inputs:  
  399.  *   - mo_window *win: The current window.
  400.  * returns: 
  401.  *   mo_succeed
  402.  * remarks: 
  403.  *   This frees the current window's texthead.  This calls mo_pull_er_over
  404.  *   directly, and needs to be smarter about handling HDF, etc.
  405.  ****************************************************************************/
  406. mo_status mo_reload_window_text (mo_window *win, int reload_images_also)
  407. {
  408.   mo_busy ();
  409.  
  410.   mo_set_current_cached_win (win);
  411.  
  412.   /* Uh oh, this is trouble... */
  413.   if (!win->current_node)
  414.     return mo_load_window_text 
  415.       (win, startup_document ? startup_document : home_document, NULL);
  416.  
  417.   /* Free all images in the current document. */
  418.   if (Rdata.reload_reloads_images || reload_images_also)
  419.     mo_zap_cached_images_here (win);
  420.  
  421.   /* Free the current document's text. */
  422.   /* REALLY we shouldn't do this until we've verified we have new text that's
  423.      actually good here -- for instance, if we have a document on display,
  424.      then go to binary transfer mode, then do reload, we should pick up the
  425.      access override here and keep the old copy up on screen. */
  426.   if (win->current_node->texthead != NULL)
  427.     {
  428.       free (win->current_node->texthead);
  429.       win->current_node->texthead = NULL;
  430.     }
  431.  
  432.   /* Set binary_transfer as per current window. */
  433.   binary_transfer = win->binary_transfer;
  434.   mo_set_current_cached_win (win);
  435.   interrupted = 0;
  436.   win->current_node->text = mo_pull_er_over (win->current_node->url, 
  437.                                              &win->current_node->texthead);
  438.   {
  439.     /* Check use_this_url_instead from HTAccess.c. */
  440.     /* IS THIS GOOD ENOUGH FOR THIS CASE??? */
  441.     extern __far  char *use_this_url_instead;
  442.     if (use_this_url_instead)
  443.       {
  444.         win->current_node->url = use_this_url_instead;
  445.       }
  446.   }
  447. #ifdef HAVE_HDF
  448.   if (win->current_node->text && 
  449.       strncmp (win->current_node->text, "<mosaic-internal-reference", 26) == 0)
  450.     {
  451.       char *text = mo_decode_internal_reference 
  452.         (win->current_node->url, win->current_node->text,
  453.          mo_url_extract_anchor (win->current_node->url));
  454.       win->current_node->text = text;
  455.       win->current_node->texthead = text;
  456.     }
  457. #endif 
  458.   
  459.   /* Clear out the cached stuff, if any exists. */
  460.   win->reloading = 1;
  461.  
  462.   mo_set_win_current_node (win, win->current_node);
  463.  
  464.   win->reloading = 0;
  465.  
  466. //  ResetAmigaGadgets();
  467.  
  468.   return mo_succeed;
  469. }
  470.  
  471.  
  472. /****************************************************************************
  473.  * name:    mo_refresh_window_text
  474.  * purpose: Reload the current window's text without pulling it over the net.
  475.  * inputs:  
  476.  *   - mo_window *win: The current window.
  477.  * returns: 
  478.  *   mo_succeed
  479.  * remarks: 
  480.  ****************************************************************************/
  481. mo_status mo_refresh_window_text (mo_window *win)
  482. {
  483.   mo_busy ();
  484.  
  485.   mo_set_current_cached_win (win);
  486.  
  487.   if (!win->current_node)
  488.     {
  489.       mo_not_busy ();
  490.       return mo_fail;
  491.     }
  492.  
  493.   /* Clear out the cached stuff, if any exists. */
  494.   win->reloading = 1;
  495.  
  496.   mo_set_win_current_node (win, win->current_node);
  497.  
  498.   mo_not_busy ();
  499.  
  500.   return mo_succeed;
  501. }
  502.  
  503. /* 22.4.95 (The day after the sale of Amiga Inc) */
  504. /* SB's note: I ran a diff on the next function vs v2.4 of XMosaic and I */
  505. /* found no obvious changes. They have just added pgp encryption, and I  */
  506. /* am leaving that out! I won't implement that. */
  507.  
  508. /****************************************************************************
  509.  * name:    mo_load_window_text
  510.  * purpose: Given a window and a raw URL, load the window.  The window
  511.  *          is assumed to already exist with a document inside, etc.
  512.  * inputs:  
  513.  *   - mo_window *win: The current window.
  514.  *   - char      *url: The URL to load.
  515.  *   - char      *ref: The reference ("parent") URL.
  516.  * returns: 
  517.  *   mo_succeed
  518.  * remarks: 
  519.  *   This is getting ugly.
  520.  ****************************************************************************/
  521. mo_status mo_load_window_text (mo_window *win, char *url, char *ref)
  522. {
  523.   char *newtext = NULL, *newtexthead = NULL;
  524.   HTMLGadClData *inst = INST_DATA(HTMLGadClass,HTML_Gad);
  525.  
  526.   mo_busy ();
  527.  
  528.   win->target_anchor = mo_url_extract_anchor (url);
  529.  
  530.   /* If we're just referencing an anchor inside a document,
  531.      do the right thing. */
  532.   if (url && *url == '#')
  533.     {
  534.       /* Now we make a copy of the current text and make sure we ask
  535.          for a new mo_node and entry in the history list. */
  536.       /* IF we're not dealing with an internal reference. */
  537.       if (strncmp (url, "#hdfref;", 8) &&
  538.           strncmp (url, "#hdfdtm;", 8))
  539.         {
  540.           if (win->current_node)
  541.             {
  542.               newtext = strdup (win->current_node->text);
  543.               newtexthead = newtext;
  544.             }
  545.           else
  546.             {
  547.               newtext = strdup ("lose");
  548.               newtexthead = newtext;
  549.             }
  550.         }
  551.       url = mo_url_canonicalize_keep_anchor 
  552.         (url, win->current_node ? win->current_node->url : "");
  553.     }
  554.   else
  555.     {
  556.       /* Get a full address for this URL. */
  557.       /* Under some circumstances we may not have a current node yet
  558.          and may wish to just run with it... so check for that. */
  559.       if (win->current_node && win->current_node->url)
  560.         {
  561.           url = mo_url_canonicalize_keep_anchor (url, win->current_node->url);
  562.         }
  563.  
  564.       /* Set binary_transfer as per current window. */
  565.       binary_transfer = win->binary_transfer;
  566.       mo_set_current_cached_win (win);
  567.  
  568.       {
  569.         char *canon = mo_url_canonicalize (url, "");
  570.         interrupted = 0;
  571.         newtext = mo_pull_er_over (canon, &newtexthead);
  572.         free (canon);
  573.       }
  574.  
  575.       {
  576.         /* Check use_this_url_instead from HTAccess.c. */
  577.         extern char *use_this_url_instead;
  578.         if (use_this_url_instead)
  579.           {
  580.             mo_here_we_are_son (url);
  581.             url = use_this_url_instead;
  582.             
  583.             /* Go get another target_anchor. */
  584.             if (win->target_anchor)
  585.               free (win->target_anchor);
  586.             win->target_anchor = mo_url_extract_anchor (url);
  587.           }
  588.       }
  589.     }
  590.  
  591. #ifdef HAVE_HDF
  592.   /* If a target anchor exists, and if it's an HDF reference, then
  593.      go decode the HDF reference and call mo_do_window_text on the
  594.      resulting text. */
  595.   if (win->target_anchor &&
  596.       strncmp (win->target_anchor, "hdfref;", 7) == 0 &&
  597.       strlen (win->target_anchor) > 8)
  598.     {
  599.       char *text;
  600.       text = (char *)mo_decode_hdfref (url, win->target_anchor);
  601.       {
  602.         /* Check use_this_url_instead from HTAccess.c. */
  603.         extern char *use_this_url_instead;
  604.         if (use_this_url_instead)
  605.           {
  606.             mo_here_we_are_son (url);
  607.             url = use_this_url_instead;
  608.             mo_load_window_text(win, url, ref);
  609.             return;
  610.           }
  611.       }
  612.       mo_do_window_text (win, url, text, text, 1, ref);
  613.     }
  614.   /* An hdfdtm reference means that we should blast the referenced
  615.      HDF data object over the output DTM port to Collage.  Currently
  616.      this can only be an image; in the future we'll do SDS's, etc. */
  617.   else if (win->target_anchor &&
  618.            strncmp (win->target_anchor, "hdfdtm;", 7) == 0 &&
  619.            strlen (win->target_anchor) > 8)
  620.     {
  621. #ifdef HAVE_DTM
  622.       /* We specifically want to make sure that the anchor is allowed
  623.          to stay in the URL, so we don't canonicalize to strip it out. */
  624.       mo_do_hdf_dtm_thang (url, &(win->target_anchor[7]));
  625. #endif
  626.  
  627.       if (win->target_anchor)
  628.         free (win->target_anchor);
  629.       win->target_anchor = NULL;
  630.  
  631.       mo_gui_done_with_icon ();
  632.       mo_not_busy ();
  633.     }
  634.   /* Assuming we have HDF, the only thing mosaic-internal-reference
  635.      currently can be is pointer to an HDF file. */
  636.   else if (newtext && strncmp (newtext, "<mosaic-internal-reference", 26) == 0)
  637.     {
  638.       char *text;
  639.       text = mo_decode_internal_reference (url, newtext, win->target_anchor);
  640.       mo_do_window_text (win, url, text, text, 1, ref);
  641.     }
  642.   else
  643. #endif
  644.   /* Now, if it's a telnet session, there should be no need
  645.      to do anything else.  Also check for override in text itself. */
  646.   if (strncmp (url, "telnet:", 7) == 0 || strncmp (url, "tn3270:", 7) == 0 ||
  647.       strncmp (url, "rlogin:", 7) == 0 ||
  648.       (newtext && strncmp (newtext, "<mosaic-access-override>", 24) == 0))
  649.     {
  650.       /* We don't need this anymore. */
  651.       free (newtext);
  652.  
  653.       /* We still want a global history entry but NOT a 
  654.          window history entry. */
  655.       mo_here_we_are_son (url);
  656.       /* ... and we want to redisplay the current window to
  657.          get the effect of the history entry today, not tomorrow. */
  658.       mo_redisplay_window (win);
  659.       /* We're not busy anymore... */
  660.       mo_gui_done_with_icon ();
  661.       mo_not_busy ();
  662.     }
  663.   else if (newtext)
  664.     {
  665.       /* Not a telnet session and not an override, but text present
  666.          (the "usual" case): */
  667.  
  668.       /* Set the window text. */
  669.       mo_do_window_text (win, url, newtext, newtexthead, 1, ref);
  670.     }
  671.   else
  672.     {
  673.       /* No text at all. */
  674.       mo_gui_done_with_icon ();
  675.       mo_not_busy ();
  676.     }
  677.  
  678.  outtahere:
  679.  
  680. //    if(!inst->have_forms)
  681.         ShowHtml_RG();
  682.  
  683.   if (win->delay_image_loads == 0) {
  684.     LoadInlinedImages();
  685.   }
  686.  
  687. //    if(inst->have_forms)
  688. //        ShowHtml_RG();
  689.  
  690.   return mo_succeed;
  691. }
  692.  
  693.  
  694. /* 22.4.95 The following function is taken from NCSA XMosaic 2.4 */
  695. /* I have removed the code dealing with PGP encryption as I see no */
  696. /* obvious way in implementing it in the rest of the code */
  697. /* /SB */
  698.  
  699. mo_status mo_post_load_window_text (mo_window *win, char *url, 
  700.                                     char *content_type, char *post_data, 
  701.                                     char *ref)
  702. {
  703.   char *newtext = NULL, *newtexthead = NULL;
  704.   HTMLGadClData *inst = INST_DATA(HTMLGadClass,HTML_Gad);
  705.  
  706.   mo_busy ();
  707.  
  708.   win->target_anchor = mo_url_extract_anchor (url);
  709.  
  710.   /* If we're just referencing an anchor inside a document,
  711.      do the right thing. */
  712.   if (url && *url == '#')
  713.     {
  714.       /* Now we make a copy of the current text and make sure we ask
  715.          for a new mo_node and entry in the history list. */
  716.       /* IF we're not dealing with an internal reference. */
  717.       if (strncmp (url, "#hdfref;", 8) &&
  718.           strncmp (url, "#hdfdtm;", 8))
  719.         {
  720.           if (win->current_node)
  721.             {
  722.               newtext = strdup (win->current_node->text);
  723.               newtexthead = newtext;
  724.             }
  725.           else
  726.             {
  727.               newtext = strdup ("lose");
  728.               newtexthead = newtext;
  729.             }
  730.         }
  731.       url = mo_url_canonicalize_keep_anchor 
  732.         (url, win->current_node ? win->current_node->url : "");
  733.     }
  734.   else
  735.     {
  736.       /* Get a full address for this URL. */
  737.       /* Under some circumstances we may not have a current node yet
  738.          and may wish to just run with it... so check for that. */
  739.       if (win->current_node && win->current_node->url)
  740.         {
  741.           url = mo_url_canonicalize_keep_anchor (url, win->current_node->url);
  742.         }
  743.  
  744.       /* Set binary_transfer as per current window. */
  745.       binary_transfer = win->binary_transfer;
  746.       mo_set_current_cached_win (win);
  747.  
  748.       {
  749.         char *canon = mo_url_canonicalize (url, "");
  750.         interrupted = 0;
  751.  
  752.         newtext = mo_post_pull_er_over (canon, content_type, post_data, 
  753.                                         &newtexthead);
  754.         free (canon);
  755.       }
  756.  
  757.       {
  758.         /* Check use_this_url_instead from HTAccess.c. */
  759.         extern char *use_this_url_instead;
  760.         if (use_this_url_instead)
  761.           {
  762.             mo_here_we_are_son (url);
  763.             url = use_this_url_instead;
  764.           }
  765.       }
  766.     }
  767.  
  768. #ifdef HAVE_HDF
  769.   /* If a target anchor exists, and if it's an HDF reference, then
  770.      go decode the HDF reference and call mo_do_window_text on the
  771.      resulting text. */
  772.   if (win->target_anchor &&
  773.       strncmp (win->target_anchor, "hdfref;", 7) == 0 &&
  774.       strlen (win->target_anchor) > 8)
  775.     {
  776.       char *text;
  777.       text = (char *)mo_decode_hdfref (url, win->target_anchor);
  778.       {
  779.         /* Check use_this_url_instead from HTAccess.c. */
  780.         extern char *use_this_url_instead;
  781.         if (use_this_url_instead)
  782.           {
  783.             mo_here_we_are_son (url);
  784.             url = use_this_url_instead;
  785.             mo_load_window_text(win, url, ref);
  786.             return;
  787.           }
  788.       }
  789.       mo_do_window_text (win, url, text, text, 1, ref);
  790.     }
  791.   /* An hdfdtm reference means that we should blast the referenced
  792.      HDF data object over the output DTM port to Collage.  Currently
  793.      this can only be an image; in the future we'll do SDS's, etc. */
  794.   else if (win->target_anchor &&
  795.            strncmp (win->target_anchor, "hdfdtm;", 7) == 0 &&
  796.            strlen (win->target_anchor) > 8)
  797.     {
  798. #ifdef HAVE_DTM
  799.       /* We specifically want to make sure that the anchor is allowed
  800.          to stay in the URL, so we don't canonicalize to strip it out. */
  801.       mo_do_hdf_dtm_thang (url, &(win->target_anchor[7]));
  802. #endif
  803.  
  804.       if (win->target_anchor)
  805.         free (win->target_anchor);
  806.       win->target_anchor = NULL;
  807.  
  808.       mo_gui_done_with_icon ();
  809.       mo_not_busy ();
  810.     }
  811.   /* Assuming we have HDF, the only thing mosaic-internal-reference
  812.      currently can be is pointer to an HDF file. */
  813.   else if (newtext && strncmp (newtext, "<mosaic-internal-reference", 26) == 0)
  814.     {
  815.       char *text;
  816.       text = mo_decode_internal_reference (url, newtext, win->target_anchor);
  817.       mo_do_window_text (win, url, text, text, 1, ref);
  818.     }
  819.   else
  820. #endif
  821.   /* Now, if it's a telnet session, there should be no need
  822.      to do anything else.  Also check for override in text itself. */
  823.   if (strncmp (url, "telnet:", 7) == 0 || strncmp (url, "tn3270:", 7) == 0 ||
  824.       strncmp (url, "rlogin:", 7) == 0 ||
  825.       (newtext && strncmp (newtext, "<mosaic-access-override>", 24) == 0))
  826.     {
  827.       /* We don't need this anymore. */
  828.       free (newtext);
  829.  
  830.       /* We still want a global history entry but NOT a 
  831.          window history entry. */
  832.       mo_here_we_are_son (url);
  833.       /* ... and we want to redisplay the current window to
  834.          get the effect of the history entry today, not tomorrow. */
  835.       mo_redisplay_window (win);
  836.       /* We're not busy anymore... */
  837.       mo_gui_done_with_icon ();
  838.       mo_not_busy ();
  839.     }
  840.   else if (newtext)
  841.     {
  842.       /* Not a telnet session and not an override, but text present
  843.          (the "usual" case): */
  844.  
  845.       /* Set the window text. */
  846.       mo_do_window_text (win, url, newtext, newtexthead, 1, ref);
  847.     }
  848.   else
  849.     {
  850.       /* No text at all. */
  851.       mo_gui_done_with_icon ();
  852.       mo_not_busy ();
  853.     }
  854.  
  855.  outtahere:
  856.     if(!inst->have_forms)
  857.         ShowHtml_RG();
  858.  
  859.  
  860.   if (win->delay_image_loads == 0) {
  861.     LoadInlinedImages();
  862.   }
  863.  
  864.     if(inst->have_forms)
  865.         ShowHtml_RG();
  866.  
  867.   return mo_succeed;
  868. }
  869.  
  870.  
  871. /****************************************************************************
  872.  * name:    mo_duplicate_window_text
  873.  * purpose: Given an old window and a new window, make a copy of the text
  874.  *          in the old window and install it in the new window.
  875.  * inputs:  
  876.  *   - mo_window *oldw: The old window.
  877.  *   - mo_window *neww: The new window.
  878.  * returns: 
  879.  *   mo_succeed
  880.  * remarks: 
  881.  *   This is how windows are cloned: a new window is created and this
  882.  *   call sets up its contents.
  883.  ****************************************************************************/
  884. mo_status mo_duplicate_window_text (mo_window *oldw, mo_window *neww)
  885. {
  886. #ifndef _AMIGA
  887.   /* We can get away with just cloning text here and forgetting
  888.      about texthead, obviously, since we're making a new copy. */
  889.   char *newtext;
  890.  
  891.   if (!oldw->current_node)
  892.     return mo_fail;
  893.  
  894.   newtext = strdup (oldw->current_node->text);
  895.  
  896.   mo_do_window_text 
  897.     (neww, strdup (oldw->current_node->url), 
  898.      newtext, newtext, TRUE, 
  899.      oldw->current_node->ref ? strdup (oldw->current_node->ref) : NULL);
  900.  
  901. #endif
  902.   return mo_succeed;
  903. }
  904.  
  905.  
  906. /****************************************************************************
  907.  * name:    mo_access_document
  908.  * purpose: Given a URL, access the document by loading the current 
  909.  *          window's text.
  910.  * inputs:  
  911.  *   - mo_window *win: The current window.
  912.  *   - char      *url: URL to access.
  913.  * returns: 
  914.  *   mo_succeed
  915.  * remarks: 
  916.  *   This should be the standard call for accessing a document.
  917.  ****************************************************************************/
  918. mo_status mo_access_document (mo_window *win, char *url)
  919. {
  920.   mo_busy ();
  921.  
  922.   mo_set_current_cached_win (win);
  923.  
  924.   mo_load_window_text (win, url, NULL);
  925.  
  926.   return mo_succeed;
  927. }
  928.  
  929.  
  930. mo_status mo_post_access_document (mo_window *win, char *url,
  931.                                    char *content_type, char *post_data)
  932. {
  933.   mo_busy ();
  934.  
  935.   mo_set_current_cached_win (win);
  936.  
  937.   mo_post_load_window_text (win, url, content_type, post_data, NULL);
  938.  
  939.   return mo_succeed;
  940. }
  941.